<template>
  <div class="postList">
    <div class="postItem" v-for="item in data" :key="item.id">
      <!-- 单个图片 -->
      <div class="onePost" v-if="item.images.length < 3">
        <div class="postCover">
          <nuxt-link :to="'/raider/detail?id='+item.id">
            <img v-if="item.images.length!=0" :src="item.images[0]" alt />
            <img v-else src="@/assets/no.png" alt />
          </nuxt-link>
        </div>
        <div class="postContent">
          <h3>
            <nuxt-link :to="'/raider/detail?id='+item.id">{{item.title}}</nuxt-link>
          </h3>
          <p>
            <nuxt-link :to="'/raider/detail?id='+item.id" v-html="item.summary"></nuxt-link>
          </p>
          <div class="postInfo">
            <div class="left">
              <span class="location">
                <i class="iconfont icon-location"></i>
                {{item.cityName}}
              </span>
              <span class="user">
                by
                <nuxt-link to>
                  <img :src="$axios.defaults.baseURL + item.account.defaultAvatar" alt />
                </nuxt-link>
                <nuxt-link to>{{item.account.nickname}}</nuxt-link>
              </span>
              <span class="look">
                <i class="iconfont icon-chakan"></i>
                {{item.watch?item.watch:0}}
              </span>
            </div>
            <span class="like">{{item.like ? item.like : 0}}赞</span>
          </div>
        </div>
      </div>
      <!-- 多个图片 -->
      <div class="morePost" v-if="item.images.length >= 3">
        <h3>
          <nuxt-link :to="'/raider/detail?id='+item.id">{{item.title}}</nuxt-link>
        </h3>
        <p>
          <nuxt-link :to="'/raider/detail?id='+item.id" v-html="item.summary"></nuxt-link>
        </p>
        <div class="postCover">
          <nuxt-link
            :to="'/raider/detail?id='+item.id"
            v-for="(imgUrl,index) in item.images.slice(0,3)"
            :key="index"
          >
            <img :src="imgUrl" alt />
          </nuxt-link>
        </div>
        <div class="postInfo">
          <div class="left">
            <span class="location">
              <i class="iconfont icon-location"></i>
              {{item.cityName}}
            </span>
            <span class="user">
              by
              <nuxt-link to>
                <img src="http://157.122.54.189:9095/assets/images/avatar.jpg" alt />
              </nuxt-link>
              <nuxt-link to>{{item.account.nickname}}</nuxt-link>
            </span>
            <span class="look">
              <i class="iconfont icon-chakan"></i>
              {{item.watch?item.watch:0}}
            </span>
          </div>
          <span class="like">{{item.like}}赞</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["data"],
};
</script>

<style lang="less" scoped>
.postItem {
  h3 {
    font-weight: 400;
    font-size: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 15px;
    a {
      &:hover {
        color: #ffa500;
      }
    }
  }
  p {
    font-size: 14px;
    line-height: 1.5;
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    margin-bottom: 15px;
    height: 65px;
    a {
      color: #666;
    }
  }
  .postInfo {
    display: flex;
    justify-content: space-between;
    .left {
      display: flex;
      align-items: center;
      color: #999;
      font-size: 12px;
      i {
        font-size: 12px;
      }
      .user {
        display: flex;
        align-items: center;
        margin: 0 10px;
        a {
          color: #ffa500;
        }
        img {
          display: block;
          width: 15px;
          height: 15px;
          margin: 0 2px 0 5px;
        }
      }
    }
    .like {
      color: #ffa500;
    }
  }
  .postCover {
    display: flex;
    justify-content: space-between;
    margin-right: 10px;
    img {
      display: block;
      width: 220px;
      height: 150px;
      object-fit: contain;
    }
  }
  .onePost {
    display: flex;
    padding: 20px 0;
    border-bottom: 1px solid #ddd;
    .postContent {
      width: 470px;
    }
  }
  .morePost {
    padding: 20px 0;
    border-bottom: 1px solid #ddd;
    .postCover {
      margin: 15px 0;
    }
  }
}
</style>